package my.suveng.oauth2.controller;

import my.suveng.model.common.interfaces.response.IMessage;
import my.suveng.model.common.response.element.ElementPage;
import my.suveng.model.common.response.element.PageQuery;
import my.suveng.oauth2.model.dto.PermissionAddDto;
import my.suveng.oauth2.model.dto.PermissionDeleteDto;
import my.suveng.oauth2.model.dto.PermissionEditDto;
import my.suveng.oauth2.model.dto.PermissionSearch;
import my.suveng.oauth2.service.db.mysql.model.entity.SysPermission;
import my.suveng.oauth2.service.user.impl.PermissionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 权限管理接口
 *
 * @author suwenguang
 **/
@RestController
@RequestMapping("/api/permission")
public class PermissionController {
    @Autowired
    private PermissionServiceImpl permissionService;

    /**
     * 权限列表
     *
     * @author suwenguang
     */
    @PostMapping("/list")
    public IMessage<ElementPage<List<SysPermission>>> permissionList(@RequestBody PageQuery<PermissionSearch> query) {
        return permissionService.list(query);
    }

    /**
     * 增加权限
     *
     * @author suwenguang
     */
    @PostMapping("/add")
    public IMessage<SysPermission> permissionAdd(@RequestBody PermissionAddDto permissionAddDto) {
        // 参数校验
        return permissionService.add(permissionAddDto);
    }

    /**
     * 修改权限
     *
     * @author suwenguang
     */
    @PostMapping("/edit")
    public IMessage<SysPermission> permissionEdit(@RequestBody PermissionEditDto permissionEditDto) {
        // 参数校验
        return permissionService.edit(permissionEditDto);
    }

    /**
     * 删除权限
     *
     * @author suwenguang
     */
    @PostMapping("/delete")
    public IMessage<Object> permissionDelete(@RequestBody PermissionDeleteDto permissionDeleteDto) {
        return permissionService.deleteById(permissionDeleteDto);
    }
}
